/**
 * Mark Fedor
 * Tony Greseth
 * CS 5551 User Interface Design
 * Section 1
 * Sai Chittilla
 * Yahtzee Program
 */

package Yahtzee;

import java.applet.AudioClip;
import java.awt.*;
import javax.swing.*;
import java.io.*;



/**
 * Graphical User Interface of the yahtzee program, contains all of the buttons
 * and connects all of the classes together
 */
public class GUI extends JFrame {

    private Die die1, die2, die3, die4, die5;
    private Dice dieGroup;
    private JPanel diePanel = new JPanel();
    private int rollCount = 0;
    private Scoreboard player1Board, player2Board;
    private boolean ones, twos, threes, fours, fives, sixes,
            threeKind, fourKind, fullHouse, smallStraight, largeStraight,
            yahtzee, chance;
    public static boolean initialRoll;
    private int player;
    private JFileChooser fileLoad;
    private JFileChooser saveFile;
    private int totalRoll;
    private boolean onePlayer;
    private File stats, names;
    private int scores[];
    private String namesArray[];
    private String player1Name, player2Name;
    private HighScores highScore;

    private AudioClip haha;


    /** Creates new form GUI */
    public GUI() {
        initComponents();
        this.setLayout(new BorderLayout());



        // shows an option dialog in which you can save the current program state
        Object[] options = {"One Player", "Two Player"};
       int n = JOptionPane.showOptionDialog(null,
               "How Many Players?",
               "Number of Players",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.QUESTION_MESSAGE,
               null,     //do not use a custom Icon
               options,  //the titles of buttons
               options[0]); //default button title
       if (n == JOptionPane.YES_OPTION)
       {
           onePlayer = true;
           player2Label.setText("NA");
           onePlayerOption.setSelected(true);
       }
       else
       {
           onePlayer = false;
           twoPlayerOption.setSelected(true);
       }

        // creates the die
        die1 = new Die();
        die2 = new Die();
        die3 = new Die();
        die4 = new Die();
        die5 = new Die();

        // initializes the die to unlocked state
        die1.setLocked(false);
        die2.setLocked(false);
        die3.setLocked(false);
        die4.setLocked(false);
        die5.setLocked(false);

        // creates the dice group which allows scores to be calculated
        dieGroup = new Dice(die1, die2, die3, die4, die5);

        // creates a panel which holds the die
        diePanel = new JPanel();

        initialRoll = true;
        totalRoll = 0;
        // adds die to the panel
        diePanel.add(die1);
        diePanel.add(die2);
        diePanel.add(die3);
        diePanel.add(die4);
        diePanel.add(die5);

        // adds the diePanel to the GUI
        this.add(diePanel);

        // adds the mouse listeners for the die in order to lock and unlock
        die1.addMouseListener(die1);
        die2.addMouseListener(die2);
        die3.addMouseListener(die3);
        die4.addMouseListener(die4);
        die5.addMouseListener(die5);
        
        player1Board = new Scoreboard();
        player2Board = new Scoreboard();

        player = 1;
        currentPlayer.setText("Player 1");

        highScore = new HighScores();
        updateHighScores();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        playerButtonGroup = new javax.swing.ButtonGroup();
        rollButton = new javax.swing.JButton();
        currentPlayer = new javax.swing.JLabel();
        possibleScore = new javax.swing.JLabel();
        scoreButtonPanel = new javax.swing.JPanel();
        USLabel = new javax.swing.JLabel();
        UBLabel = new javax.swing.JLabel();
        LBLabel = new javax.swing.JLabel();
        totalScoreLabel = new javax.swing.JLabel();
        yahtzeeBonusLabel = new javax.swing.JLabel();
        player1Label = new java.awt.Label();
        player2Label = new java.awt.Label();
        oneSixPanel = new javax.swing.JPanel();
        onesButton = new javax.swing.JButton();
        twosButton = new javax.swing.JButton();
        threesButton = new javax.swing.JButton();
        foursButton = new javax.swing.JButton();
        fivesButton = new javax.swing.JButton();
        sixesButton = new javax.swing.JButton();
        bottomButtonPanel = new javax.swing.JPanel();
        threekindButton = new javax.swing.JButton();
        fourkindButton = new javax.swing.JButton();
        fullhouseButton = new javax.swing.JButton();
        smStraightButton = new javax.swing.JButton();
        lgStraightButton = new javax.swing.JButton();
        yahtzeeButton = new javax.swing.JButton();
        chanceButton = new javax.swing.JButton();
        topScorePanel = new javax.swing.JPanel();
        tOneField = new javax.swing.JTextField();
        yOneField = new javax.swing.JTextField();
        tTwoField = new javax.swing.JTextField();
        yTwoField = new javax.swing.JTextField();
        tThreeField = new javax.swing.JTextField();
        yThreeField = new javax.swing.JTextField();
        tFourField = new javax.swing.JTextField();
        yFourField = new javax.swing.JTextField();
        tFiveField = new javax.swing.JTextField();
        yFiveField = new javax.swing.JTextField();
        tSixField = new javax.swing.JTextField();
        ySixField = new javax.swing.JTextField();
        tUpperScore = new javax.swing.JTextField();
        yUpperScore = new javax.swing.JTextField();
        tBonusField = new javax.swing.JTextField();
        yBonusField = new javax.swing.JTextField();
        bottomScorePanel = new javax.swing.JPanel();
        tThreeKindField = new javax.swing.JTextField();
        yThreeKindField = new javax.swing.JTextField();
        tFourKindField = new javax.swing.JTextField();
        yFourKindField = new javax.swing.JTextField();
        tFullHouseField = new javax.swing.JTextField();
        yFullHouseField = new javax.swing.JTextField();
        tSmStField = new javax.swing.JTextField();
        ySmStField = new javax.swing.JTextField();
        tLgStField = new javax.swing.JTextField();
        yLgStField = new javax.swing.JTextField();
        tYahtzeeField = new javax.swing.JTextField();
        yYahtzeeField = new javax.swing.JTextField();
        tChanceField = new javax.swing.JTextField();
        yChanceField = new javax.swing.JTextField();
        tYahtzeeBonus = new javax.swing.JTextField();
        yYahtzeeBonus = new javax.swing.JTextField();
        tLowerScoreField = new javax.swing.JTextField();
        yLowerScoreField = new javax.swing.JTextField();
        tTotalScore = new javax.swing.JTextField();
        yTotalScore = new javax.swing.JTextField();
        quitButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        highScores = new javax.swing.JTextArea();
        menuBar = new javax.swing.JMenuBar();
        exitMenuItem = new javax.swing.JMenu();
        newGame = new javax.swing.JMenuItem();
        saveItem = new javax.swing.JMenuItem();
        openItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        exitMenu = new javax.swing.JMenuItem();
        playerMenu = new javax.swing.JMenu();
        onePlayerOption = new javax.swing.JRadioButtonMenuItem();
        twoPlayerOption = new javax.swing.JRadioButtonMenuItem();
        helpMenu = new javax.swing.JMenu();
        helpMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Yahtzee");

        rollButton.setMnemonic('R');
        rollButton.setText("Roll");
        rollButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rollButtonActionPerformed(evt);
            }
        });

        currentPlayer.setFont(new java.awt.Font("Tahoma", 1, 18));
        currentPlayer.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        currentPlayer.setText("jLabel1");
        currentPlayer.setBorder(javax.swing.BorderFactory.createTitledBorder("Current Player"));

        possibleScore.setBackground(new java.awt.Color(51, 51, 255));
        possibleScore.setFont(new java.awt.Font("Tahoma", 1, 18));
        possibleScore.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        possibleScore.setBorder(javax.swing.BorderFactory.createTitledBorder("Possible Score"));

        scoreButtonPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Scoring"));
        scoreButtonPanel.setMaximumSize(new java.awt.Dimension(350, 580));
        scoreButtonPanel.setMinimumSize(new java.awt.Dimension(350, 580));
        scoreButtonPanel.setPreferredSize(new java.awt.Dimension(350, 580));
        scoreButtonPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        USLabel.setText("Upper Score");
        scoreButtonPanel.add(USLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 250, -1, -1));

        UBLabel.setText("Bonus");
        scoreButtonPanel.add(UBLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 280, -1, -1));

        LBLabel.setText("Lower Score");
        scoreButtonPanel.add(LBLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 580, -1, -1));

        totalScoreLabel.setText("Total");
        scoreButtonPanel.add(totalScoreLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 610, -1, -1));

        yahtzeeBonusLabel.setText("Yahtzee Bonus");
        scoreButtonPanel.add(yahtzeeBonusLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 550, -1, -1));

        player1Label.setAlignment(java.awt.Label.CENTER);
        player1Label.setText("Player 1");
        scoreButtonPanel.add(player1Label, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 30, -1, -1));

        player2Label.setAlignment(java.awt.Label.CENTER);
        player2Label.setText("Player 2");
        scoreButtonPanel.add(player2Label, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 30, -1, -1));

        oneSixPanel.setLayout(new java.awt.GridLayout(6, 1, 0, 10));

        onesButton.setText("One's");
        onesButton.setMaximumSize(new java.awt.Dimension(123, 20));
        onesButton.setMinimumSize(new java.awt.Dimension(123, 20));
        onesButton.setPreferredSize(new java.awt.Dimension(123, 20));
        onesButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onesButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onesButtonMouseExited(evt);
            }
        });
        onesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onesButtonActionPerformed(evt);
            }
        });
        oneSixPanel.add(onesButton);

        twosButton.setText("Two's");
        twosButton.setMaximumSize(new java.awt.Dimension(123, 20));
        twosButton.setMinimumSize(new java.awt.Dimension(123, 20));
        twosButton.setPreferredSize(new java.awt.Dimension(123, 20));
        twosButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                twosButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                twosButtonMouseExited(evt);
            }
        });
        twosButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                twosButtonActionPerformed(evt);
            }
        });
        oneSixPanel.add(twosButton);

        threesButton.setText("Three's");
        threesButton.setMaximumSize(new java.awt.Dimension(123, 20));
        threesButton.setMinimumSize(new java.awt.Dimension(123, 20));
        threesButton.setPreferredSize(new java.awt.Dimension(123, 20));
        threesButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                threesButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                threesButtonMouseExited(evt);
            }
        });
        threesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                threesButtonActionPerformed(evt);
            }
        });
        oneSixPanel.add(threesButton);

        foursButton.setText("Four's");
        foursButton.setMaximumSize(new java.awt.Dimension(123, 20));
        foursButton.setMinimumSize(new java.awt.Dimension(123, 20));
        foursButton.setPreferredSize(new java.awt.Dimension(123, 20));
        foursButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                foursButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                foursButtonMouseExited(evt);
            }
        });
        foursButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                foursButtonActionPerformed(evt);
            }
        });
        oneSixPanel.add(foursButton);

        fivesButton.setText("Five's");
        fivesButton.setMaximumSize(new java.awt.Dimension(123, 20));
        fivesButton.setMinimumSize(new java.awt.Dimension(123, 20));
        fivesButton.setPreferredSize(new java.awt.Dimension(123, 20));
        fivesButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                fivesButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                fivesButtonMouseExited(evt);
            }
        });
        fivesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fivesButtonActionPerformed(evt);
            }
        });
        oneSixPanel.add(fivesButton);

        sixesButton.setText("Six's");
        sixesButton.setMaximumSize(new java.awt.Dimension(123, 20));
        sixesButton.setMinimumSize(new java.awt.Dimension(123, 20));
        sixesButton.setPreferredSize(new java.awt.Dimension(123, 20));
        sixesButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                sixesButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                sixesButtonMouseExited(evt);
            }
        });
        sixesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sixesButtonActionPerformed(evt);
            }
        });
        oneSixPanel.add(sixesButton);

        scoreButtonPanel.add(oneSixPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(16, 70, 150, -1));

        bottomButtonPanel.setLayout(new java.awt.GridLayout(7, 1, 0, 10));

        threekindButton.setText("3 of a Kind");
        threekindButton.setMaximumSize(new java.awt.Dimension(123, 20));
        threekindButton.setMinimumSize(new java.awt.Dimension(123, 20));
        threekindButton.setPreferredSize(new java.awt.Dimension(123, 20));
        threekindButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                threekindButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                threekindButtonMouseExited(evt);
            }
        });
        threekindButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                threekindButtonActionPerformed(evt);
            }
        });
        bottomButtonPanel.add(threekindButton);

        fourkindButton.setText("4 of a Kind");
        fourkindButton.setMaximumSize(new java.awt.Dimension(123, 20));
        fourkindButton.setMinimumSize(new java.awt.Dimension(123, 20));
        fourkindButton.setPreferredSize(new java.awt.Dimension(123, 20));
        fourkindButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                fourkindButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                fourkindButtonMouseExited(evt);
            }
        });
        fourkindButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fourkindButtonActionPerformed(evt);
            }
        });
        bottomButtonPanel.add(fourkindButton);

        fullhouseButton.setText("Full House (25 pts)");
        fullhouseButton.setMaximumSize(new java.awt.Dimension(123, 20));
        fullhouseButton.setMinimumSize(new java.awt.Dimension(123, 20));
        fullhouseButton.setPreferredSize(new java.awt.Dimension(123, 20));
        fullhouseButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                fullhouseButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                fullhouseButtonMouseExited(evt);
            }
        });
        fullhouseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fullhouseButtonActionPerformed(evt);
            }
        });
        bottomButtonPanel.add(fullhouseButton);

        smStraightButton.setText("Small Straight (30 pts)");
        smStraightButton.setMaximumSize(new java.awt.Dimension(123, 20));
        smStraightButton.setMinimumSize(new java.awt.Dimension(123, 20));
        smStraightButton.setPreferredSize(new java.awt.Dimension(123, 20));
        smStraightButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smStraightButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smStraightButtonMouseExited(evt);
            }
        });
        smStraightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smStraightButtonActionPerformed(evt);
            }
        });
        bottomButtonPanel.add(smStraightButton);

        lgStraightButton.setText("Large Straight (40 pts)");
        lgStraightButton.setMaximumSize(new java.awt.Dimension(123, 20));
        lgStraightButton.setMinimumSize(new java.awt.Dimension(123, 20));
        lgStraightButton.setPreferredSize(new java.awt.Dimension(123, 20));
        lgStraightButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lgStraightButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lgStraightButtonMouseExited(evt);
            }
        });
        lgStraightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lgStraightButtonActionPerformed(evt);
            }
        });
        bottomButtonPanel.add(lgStraightButton);

        yahtzeeButton.setText("Yahtzee (50 pts)");
        yahtzeeButton.setMaximumSize(new java.awt.Dimension(123, 20));
        yahtzeeButton.setMinimumSize(new java.awt.Dimension(123, 20));
        yahtzeeButton.setPreferredSize(new java.awt.Dimension(123, 20));
        yahtzeeButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                yahtzeeButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                yahtzeeButtonMouseExited(evt);
            }
        });
        yahtzeeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yahtzeeButtonActionPerformed(evt);
            }
        });
        bottomButtonPanel.add(yahtzeeButton);

        chanceButton.setText("Chance ");
        chanceButton.setMaximumSize(new java.awt.Dimension(123, 20));
        chanceButton.setMinimumSize(new java.awt.Dimension(123, 20));
        chanceButton.setPreferredSize(new java.awt.Dimension(123, 20));
        chanceButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                chanceButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                chanceButtonMouseExited(evt);
            }
        });
        chanceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chanceButtonActionPerformed(evt);
            }
        });
        bottomButtonPanel.add(chanceButton);

        scoreButtonPanel.add(bottomButtonPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 320, 150, 215));

        topScorePanel.setLayout(new java.awt.GridLayout(8, 2, 35, 10));

        tOneField.setColumns(2);
        tOneField.setEditable(false);
        tOneField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tOneField.setMaximumSize(new java.awt.Dimension(42, 20));
        tOneField.setMinimumSize(new java.awt.Dimension(42, 20));
        tOneField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tOneFieldActionPerformed(evt);
            }
        });
        topScorePanel.add(tOneField);

        yOneField.setColumns(2);
        yOneField.setEditable(false);
        yOneField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yOneField.setMaximumSize(new java.awt.Dimension(42, 20));
        yOneField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(yOneField);

        tTwoField.setColumns(2);
        tTwoField.setEditable(false);
        tTwoField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tTwoField.setMaximumSize(new java.awt.Dimension(42, 20));
        tTwoField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(tTwoField);

        yTwoField.setColumns(2);
        yTwoField.setEditable(false);
        yTwoField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yTwoField.setMaximumSize(new java.awt.Dimension(42, 20));
        yTwoField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(yTwoField);

        tThreeField.setColumns(2);
        tThreeField.setEditable(false);
        tThreeField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tThreeField.setMaximumSize(new java.awt.Dimension(42, 20));
        tThreeField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(tThreeField);

        yThreeField.setColumns(2);
        yThreeField.setEditable(false);
        yThreeField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yThreeField.setMaximumSize(new java.awt.Dimension(42, 20));
        yThreeField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(yThreeField);

        tFourField.setColumns(2);
        tFourField.setEditable(false);
        tFourField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tFourField.setMaximumSize(new java.awt.Dimension(42, 20));
        tFourField.setMinimumSize(new java.awt.Dimension(42, 20));
        tFourField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tFourFieldActionPerformed(evt);
            }
        });
        topScorePanel.add(tFourField);

        yFourField.setColumns(2);
        yFourField.setEditable(false);
        yFourField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yFourField.setMaximumSize(new java.awt.Dimension(42, 20));
        yFourField.setMinimumSize(new java.awt.Dimension(42, 20));
        yFourField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yFourFieldActionPerformed(evt);
            }
        });
        topScorePanel.add(yFourField);

        tFiveField.setColumns(2);
        tFiveField.setEditable(false);
        tFiveField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tFiveField.setMaximumSize(new java.awt.Dimension(42, 20));
        tFiveField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(tFiveField);

        yFiveField.setColumns(2);
        yFiveField.setEditable(false);
        yFiveField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yFiveField.setMaximumSize(new java.awt.Dimension(42, 20));
        yFiveField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(yFiveField);

        tSixField.setColumns(2);
        tSixField.setEditable(false);
        tSixField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tSixField.setMaximumSize(new java.awt.Dimension(42, 20));
        tSixField.setMinimumSize(new java.awt.Dimension(42, 20));
        tSixField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tSixFieldActionPerformed(evt);
            }
        });
        topScorePanel.add(tSixField);

        ySixField.setColumns(2);
        ySixField.setEditable(false);
        ySixField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        ySixField.setMaximumSize(new java.awt.Dimension(42, 20));
        ySixField.setMinimumSize(new java.awt.Dimension(42, 20));
        ySixField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ySixFieldActionPerformed(evt);
            }
        });
        topScorePanel.add(ySixField);

        tUpperScore.setColumns(2);
        tUpperScore.setEditable(false);
        tUpperScore.setFont(new java.awt.Font("Tahoma", 1, 11));
        tUpperScore.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tUpperScore.setText("            ");
        tUpperScore.setMaximumSize(new java.awt.Dimension(42, 20));
        tUpperScore.setMinimumSize(new java.awt.Dimension(42, 20));
        tUpperScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tUpperScoreActionPerformed(evt);
            }
        });
        topScorePanel.add(tUpperScore);

        yUpperScore.setColumns(2);
        yUpperScore.setEditable(false);
        yUpperScore.setFont(new java.awt.Font("Tahoma", 1, 11));
        yUpperScore.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yUpperScore.setText("            ");
        yUpperScore.setMaximumSize(new java.awt.Dimension(42, 20));
        yUpperScore.setMinimumSize(new java.awt.Dimension(42, 20));
        yUpperScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yUpperScoreActionPerformed(evt);
            }
        });
        topScorePanel.add(yUpperScore);

        tBonusField.setColumns(2);
        tBonusField.setEditable(false);
        tBonusField.setFont(new java.awt.Font("Tahoma", 1, 11));
        tBonusField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tBonusField.setText("            ");
        tBonusField.setMaximumSize(new java.awt.Dimension(42, 20));
        tBonusField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(tBonusField);

        yBonusField.setColumns(2);
        yBonusField.setEditable(false);
        yBonusField.setFont(new java.awt.Font("Tahoma", 1, 11));
        yBonusField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yBonusField.setText("            ");
        yBonusField.setMaximumSize(new java.awt.Dimension(42, 20));
        yBonusField.setMinimumSize(new java.awt.Dimension(42, 20));
        topScorePanel.add(yBonusField);

        scoreButtonPanel.add(topScorePanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 70, -1, -1));

        bottomScorePanel.setLayout(new java.awt.GridLayout(10, 2, 35, 10));

        tThreeKindField.setColumns(2);
        tThreeKindField.setEditable(false);
        tThreeKindField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tThreeKindField.setText("            ");
        tThreeKindField.setMaximumSize(new java.awt.Dimension(42, 20));
        tThreeKindField.setMinimumSize(new java.awt.Dimension(42, 20));
        tThreeKindField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tThreeKindFieldActionPerformed(evt);
            }
        });
        bottomScorePanel.add(tThreeKindField);

        yThreeKindField.setColumns(2);
        yThreeKindField.setEditable(false);
        yThreeKindField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yThreeKindField.setText("            ");
        yThreeKindField.setMaximumSize(new java.awt.Dimension(42, 20));
        yThreeKindField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(yThreeKindField);

        tFourKindField.setColumns(2);
        tFourKindField.setEditable(false);
        tFourKindField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tFourKindField.setText("            ");
        tFourKindField.setMaximumSize(new java.awt.Dimension(42, 20));
        tFourKindField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tFourKindField);

        yFourKindField.setColumns(2);
        yFourKindField.setEditable(false);
        yFourKindField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yFourKindField.setText("            ");
        yFourKindField.setMaximumSize(new java.awt.Dimension(42, 20));
        yFourKindField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(yFourKindField);

        tFullHouseField.setColumns(2);
        tFullHouseField.setEditable(false);
        tFullHouseField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tFullHouseField.setText("            ");
        tFullHouseField.setMaximumSize(new java.awt.Dimension(42, 20));
        tFullHouseField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tFullHouseField);

        yFullHouseField.setColumns(2);
        yFullHouseField.setEditable(false);
        yFullHouseField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yFullHouseField.setText("            ");
        yFullHouseField.setMaximumSize(new java.awt.Dimension(42, 20));
        yFullHouseField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(yFullHouseField);

        tSmStField.setColumns(2);
        tSmStField.setEditable(false);
        tSmStField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tSmStField.setText("            ");
        tSmStField.setMaximumSize(new java.awt.Dimension(42, 20));
        tSmStField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tSmStField);

        ySmStField.setColumns(2);
        ySmStField.setEditable(false);
        ySmStField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        ySmStField.setText("            ");
        ySmStField.setMaximumSize(new java.awt.Dimension(42, 20));
        ySmStField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(ySmStField);

        tLgStField.setColumns(2);
        tLgStField.setEditable(false);
        tLgStField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tLgStField.setText("            ");
        tLgStField.setMaximumSize(new java.awt.Dimension(42, 20));
        tLgStField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tLgStField);

        yLgStField.setColumns(2);
        yLgStField.setEditable(false);
        yLgStField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yLgStField.setText("            ");
        yLgStField.setMaximumSize(new java.awt.Dimension(42, 20));
        yLgStField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(yLgStField);

        tYahtzeeField.setColumns(2);
        tYahtzeeField.setEditable(false);
        tYahtzeeField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tYahtzeeField.setText("            ");
        tYahtzeeField.setMaximumSize(new java.awt.Dimension(42, 20));
        tYahtzeeField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tYahtzeeField);

        yYahtzeeField.setColumns(2);
        yYahtzeeField.setEditable(false);
        yYahtzeeField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yYahtzeeField.setText("            ");
        yYahtzeeField.setMaximumSize(new java.awt.Dimension(42, 20));
        yYahtzeeField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(yYahtzeeField);

        tChanceField.setColumns(2);
        tChanceField.setEditable(false);
        tChanceField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tChanceField.setText("            ");
        tChanceField.setMaximumSize(new java.awt.Dimension(42, 20));
        tChanceField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tChanceField);

        yChanceField.setColumns(2);
        yChanceField.setEditable(false);
        yChanceField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yChanceField.setText("            ");
        yChanceField.setMaximumSize(new java.awt.Dimension(42, 20));
        yChanceField.setMinimumSize(new java.awt.Dimension(42, 20));
        yChanceField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yChanceFieldActionPerformed(evt);
            }
        });
        bottomScorePanel.add(yChanceField);

        tYahtzeeBonus.setColumns(2);
        tYahtzeeBonus.setEditable(false);
        tYahtzeeBonus.setFont(new java.awt.Font("Tahoma", 1, 11));
        tYahtzeeBonus.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tYahtzeeBonus.setText("            ");
        tYahtzeeBonus.setMaximumSize(new java.awt.Dimension(42, 20));
        tYahtzeeBonus.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tYahtzeeBonus);

        yYahtzeeBonus.setColumns(2);
        yYahtzeeBonus.setEditable(false);
        yYahtzeeBonus.setFont(new java.awt.Font("Tahoma", 1, 11));
        yYahtzeeBonus.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yYahtzeeBonus.setText("            ");
        yYahtzeeBonus.setMaximumSize(new java.awt.Dimension(42, 20));
        yYahtzeeBonus.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(yYahtzeeBonus);

        tLowerScoreField.setColumns(2);
        tLowerScoreField.setEditable(false);
        tLowerScoreField.setFont(new java.awt.Font("Tahoma", 1, 11));
        tLowerScoreField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tLowerScoreField.setText("            ");
        tLowerScoreField.setMaximumSize(new java.awt.Dimension(42, 20));
        tLowerScoreField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tLowerScoreField);

        yLowerScoreField.setColumns(2);
        yLowerScoreField.setEditable(false);
        yLowerScoreField.setFont(new java.awt.Font("Tahoma", 1, 11));
        yLowerScoreField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yLowerScoreField.setText("            ");
        yLowerScoreField.setMaximumSize(new java.awt.Dimension(42, 20));
        yLowerScoreField.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(yLowerScoreField);

        tTotalScore.setColumns(2);
        tTotalScore.setEditable(false);
        tTotalScore.setFont(new java.awt.Font("Tahoma", 1, 11));
        tTotalScore.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tTotalScore.setText("            ");
        tTotalScore.setMaximumSize(new java.awt.Dimension(42, 20));
        tTotalScore.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(tTotalScore);

        yTotalScore.setColumns(2);
        yTotalScore.setEditable(false);
        yTotalScore.setFont(new java.awt.Font("Tahoma", 1, 11));
        yTotalScore.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        yTotalScore.setText("            ");
        yTotalScore.setMaximumSize(new java.awt.Dimension(42, 20));
        yTotalScore.setMinimumSize(new java.awt.Dimension(42, 20));
        bottomScorePanel.add(yTotalScore);

        scoreButtonPanel.add(bottomScorePanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 320, -1, 311));

        quitButton.setText("Quit");
        quitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitButtonActionPerformed(evt);
            }
        });

        highScores.setBackground(new java.awt.Color(240, 240, 240));
        highScores.setColumns(10);
        highScores.setEditable(false);
        highScores.setFont(new java.awt.Font("Tahoma", 0, 13));
        highScores.setRows(5);
        highScores.setBorder(javax.swing.BorderFactory.createTitledBorder("Top 10"));
        jScrollPane1.setViewportView(highScores);

        exitMenuItem.setMnemonic('F');
        exitMenuItem.setText("File");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });

        newGame.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        newGame.setText("New Game");
        newGame.setToolTipText("Make a new game");
        newGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newGameActionPerformed(evt);
            }
        });
        exitMenuItem.add(newGame);

        saveItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveItem.setText("Save");
        saveItem.setToolTipText("Save a Game");
        saveItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveItemActionPerformed(evt);
            }
        });
        exitMenuItem.add(saveItem);

        openItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openItem.setText("Open");
        openItem.setToolTipText("Load an old game");
        openItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openItemActionPerformed(evt);
            }
        });
        exitMenuItem.add(openItem);
        exitMenuItem.add(jSeparator1);

        exitMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK));
        exitMenu.setText("Exit");
        exitMenu.setToolTipText("Exit the program");
        exitMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuActionPerformed(evt);
            }
        });
        exitMenuItem.add(exitMenu);

        menuBar.add(exitMenuItem);

        playerMenu.setMnemonic('P');
        playerMenu.setText("Players");
        playerMenu.setToolTipText("Change the amount of players");

        playerButtonGroup.add(onePlayerOption);
        onePlayerOption.setMnemonic('O');
        onePlayerOption.setSelected(true);
        onePlayerOption.setText("One Player");
        onePlayerOption.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onePlayerOptionActionPerformed(evt);
            }
        });
        playerMenu.add(onePlayerOption);

        playerButtonGroup.add(twoPlayerOption);
        twoPlayerOption.setMnemonic('T');
        twoPlayerOption.setText("Two Player");
        twoPlayerOption.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                twoPlayerOptionActionPerformed(evt);
            }
        });
        playerMenu.add(twoPlayerOption);

        menuBar.add(playerMenu);

        helpMenu.setText("Help");
        helpMenu.setToolTipText("Yahtzee Help");

        helpMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, 0));
        helpMenuItem.setText("Help");
        helpMenuItem.setToolTipText("Yahtzee Rules");
        helpMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(helpMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);
        menuBar.add(Box.createHorizontalGlue());
        menuBar.add(helpMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1)
                    .addComponent(possibleScore, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(currentPlayer, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                .addGap(44, 44, 44)
                .addComponent(scoreButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(rollButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(quitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(34, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(112, 112, 112)
                        .addComponent(rollButton)
                        .addGap(18, 18, 18)
                        .addComponent(quitButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(79, 79, 79)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(scoreButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 669, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(possibleScore, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(currentPlayer, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(186, 186, 186)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(113, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rollButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rollButtonActionPerformed
        // disables the ability to change the number of players
        onePlayerOption.setEnabled(false);
        twoPlayerOption.setEnabled(false);
        // disables all of the pre-recorded items
        disableAll();
        // rolls the nice
        die1.roll();
        die2.roll();
        die3.roll();
        die4.roll();
        die5.roll();

        // repaints the dice
        repaint();
        rollCount++;
        if (rollCount == 3)
            rollButton.setEnabled(false);

        // creates a new diegroup in order to calculate the scores
        dieGroup = new Dice(die1, die2, die3, die4, die5);

        // no longer the first roll
        initialRoll = false;
        // enables all of the buttons that can be scored
        enableAll();

    }//GEN-LAST:event_rollButtonActionPerformed

    private void onesButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_onesButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getOnes()));
}//GEN-LAST:event_onesButtonMouseEntered

    private void onesButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_onesButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_onesButtonMouseExited

    private void onesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onesButtonActionPerformed
        // checks if its the first roll or not
        if (rollCount != 0)
        {
            // determines the player in which is scoring
            if (player == 1)
            {
                // checks for a yahtzee
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                // gets the score
                yOneField.setText(Integer.toString(dieGroup.getOnes()));
                // updates the scoreboard
                player1Board.update(0);
                player1Board.ones = true;                
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yUpperScore.setText(Integer.toString(player1Board.getTop()));
                yBonusField.setText(Integer.toString(player1Board.getTopBonus()));
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tOneField.setText(Integer.toString(dieGroup.getOnes()));
                player2Board.update(0);
                player2Board.ones = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tUpperScore.setText(Integer.toString(player2Board.getTop()));
                tBonusField.setText(Integer.toString(player2Board.getTopBonus()));
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));                
            }
            else
            {
                // shouldn't happen
            }
            // resets all of the buttons and counts
            rollCount = 0;
            rollButton.setEnabled(true);
            onesButton.setEnabled(false);
            ones = true;
            // unlocks the die
            unlock();
            // repaints the die
            repaintDie();
            // disables all of the buttons
            disableAll();
            // resets the initial roll
            initialRoll = true;
            // checks if the game is over
            checkWin();
        }
}//GEN-LAST:event_onesButtonActionPerformed

    private void twosButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_twosButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getTwos()));
}//GEN-LAST:event_twosButtonMouseEntered

    private void twosButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_twosButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_twosButtonMouseExited

    private void twosButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_twosButtonActionPerformed
        checkWin();
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yTwoField.setText(Integer.toString(dieGroup.getTwos()));
                player1Board.update(1);
                player1Board.twos = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yUpperScore.setText(Integer.toString(player1Board.getTop()));
                yBonusField.setText(Integer.toString(player1Board.getTopBonus()));
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tTwoField.setText(Integer.toString(dieGroup.getTwos()));
                player2Board.update(1);
                player2Board.twos = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tUpperScore.setText(Integer.toString(player2Board.getTop()));
                tBonusField.setText(Integer.toString(player2Board.getTopBonus()));
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            twosButton.setEnabled(false);
            twos = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
        }
}//GEN-LAST:event_twosButtonActionPerformed

    private void threesButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_threesButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getThrees()));
}//GEN-LAST:event_threesButtonMouseEntered

    private void threesButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_threesButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_threesButtonMouseExited

    private void threesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_threesButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yThreeField.setText(Integer.toString(dieGroup.getThrees()));
                player1Board.update(2);
                player1Board.threes = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yUpperScore.setText(Integer.toString(player1Board.getTop()));
                yBonusField.setText(Integer.toString(player1Board.getTopBonus()));
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tThreeField.setText(Integer.toString(dieGroup.getThrees()));
                player2Board.update(2);
                player2Board.threes = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tUpperScore.setText(Integer.toString(player2Board.getTop()));
                tBonusField.setText(Integer.toString(player2Board.getTopBonus()));
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            threesButton.setEnabled(false);
            threes = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();

        }
}//GEN-LAST:event_threesButtonActionPerformed

    private void foursButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_foursButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getFours()));
}//GEN-LAST:event_foursButtonMouseEntered

    private void foursButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_foursButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_foursButtonMouseExited

    private void foursButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_foursButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yFourField.setText(Integer.toString(dieGroup.getFours()));
                player1Board.update(3);
                player1Board.fours = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yUpperScore.setText(Integer.toString(player1Board.getTop()));
                yBonusField.setText(Integer.toString(player1Board.getTopBonus()));
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tFourField.setText(Integer.toString(dieGroup.getFours()));
                player2Board.update(3);
                player2Board.fours = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tUpperScore.setText(Integer.toString(player2Board.getTop()));
                tBonusField.setText(Integer.toString(player2Board.getTopBonus()));
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            foursButton.setEnabled(false);
            fours = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_foursButtonActionPerformed

    private void fivesButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fivesButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getFives()));
}//GEN-LAST:event_fivesButtonMouseEntered

    private void fivesButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fivesButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_fivesButtonMouseExited

    private void fivesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fivesButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yFiveField.setText(Integer.toString(dieGroup.getFives()));
                player1Board.update(4);
                player1Board.fives = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yUpperScore.setText(Integer.toString(player1Board.getTop()));
                yBonusField.setText(Integer.toString(player1Board.getTopBonus()));
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tFiveField.setText(Integer.toString(dieGroup.getFives()));
                player2Board.update(4);
                player2Board.fives = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tUpperScore.setText(Integer.toString(player2Board.getTop()));
                tBonusField.setText(Integer.toString(player2Board.getTopBonus()));
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            fivesButton.setEnabled(false);
            fives = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_fivesButtonActionPerformed

    private void sixesButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sixesButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getSixes()));
}//GEN-LAST:event_sixesButtonMouseEntered

    private void sixesButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sixesButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_sixesButtonMouseExited

    private void sixesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sixesButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                ySixField.setText(Integer.toString(dieGroup.getSixes()));
                player1Board.update(5);
                player1Board.sixes = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yUpperScore.setText(Integer.toString(player1Board.getTop()));
                yBonusField.setText(Integer.toString(player1Board.getTopBonus()));
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tSixField.setText(Integer.toString(dieGroup.getSixes()));
                player2Board.update(5);
                player2Board.sixes = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tUpperScore.setText(Integer.toString(player2Board.getTop()));
                tBonusField.setText(Integer.toString(player2Board.getTopBonus()));
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            sixesButton.setEnabled(false);
            sixes = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_sixesButtonActionPerformed

    private void threekindButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_threekindButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getThreeOfAKind()));
}//GEN-LAST:event_threekindButtonMouseEntered

    private void threekindButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_threekindButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_threekindButtonMouseExited

    private void threekindButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_threekindButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yThreeKindField.setText(Integer.toString(dieGroup.getThreeOfAKind()));
                player1Board.update(6);
                player1Board.threeKind = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yLowerScoreField.setText(Integer.toString(player1Board.getBottom()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tThreeKindField.setText(Integer.toString(dieGroup.getThreeOfAKind()));
                player2Board.update(6);
                player2Board.threeKind = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tLowerScoreField.setText(Integer.toString(player2Board.getBottom()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            threekindButton.setEnabled(false);
            threeKind = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_threekindButtonActionPerformed

    private void fourkindButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fourkindButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getFourOfAKind()));
}//GEN-LAST:event_fourkindButtonMouseEntered

    private void fourkindButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fourkindButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_fourkindButtonMouseExited

    private void fourkindButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fourkindButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yFourKindField.setText(Integer.toString(dieGroup.getFourOfAKind()));
                player1Board.update(7);
                player1Board.fourKind = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yLowerScoreField.setText(Integer.toString(player1Board.getBottom()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tFourKindField.setText(Integer.toString(dieGroup.getFourOfAKind()));
                player2Board.update(7);
                player2Board.fourKind = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tLowerScoreField.setText(Integer.toString(player2Board.getBottom()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            fourkindButton.setEnabled(false);
            fourKind = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_fourkindButtonActionPerformed

    private void fullhouseButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fullhouseButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getFullHouse()));
}//GEN-LAST:event_fullhouseButtonMouseEntered

    private void fullhouseButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fullhouseButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_fullhouseButtonMouseExited

    private void fullhouseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fullhouseButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yFullHouseField.setText(Integer.toString(dieGroup.getFullHouse()));
                player1Board.update(8);
                player1Board.fullHouse = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yLowerScoreField.setText(Integer.toString(player1Board.getBottom()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tFullHouseField.setText(Integer.toString(dieGroup.getFullHouse()));
                player2Board.update(8);
                player2Board.fullHouse = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tLowerScoreField.setText(Integer.toString(player2Board.getBottom()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            fullhouseButton.setEnabled(false);
            fullHouse = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_fullhouseButtonActionPerformed

    private void smStraightButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_smStraightButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getSmallStraight()));
}//GEN-LAST:event_smStraightButtonMouseEntered

    private void smStraightButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_smStraightButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_smStraightButtonMouseExited

    private void smStraightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smStraightButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                ySmStField.setText(Integer.toString(dieGroup.getSmallStraight()));
                player1Board.update(9);
                player1Board.smallStraight = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yLowerScoreField.setText(Integer.toString(player1Board.getBottom()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tSmStField.setText(Integer.toString(dieGroup.getSmallStraight()));
                player2Board.update(9);
                player2Board.smallStraight = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tLowerScoreField.setText(Integer.toString(player2Board.getBottom()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            smStraightButton.setEnabled(false);
            smallStraight = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_smStraightButtonActionPerformed

    private void lgStraightButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lgStraightButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getLargeStraight()));
}//GEN-LAST:event_lgStraightButtonMouseEntered

    private void lgStraightButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lgStraightButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_lgStraightButtonMouseExited

    private void lgStraightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lgStraightButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yLgStField.setText(Integer.toString(dieGroup.getLargeStraight()));
                player1Board.update(10);
                player1Board.largeStraight = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yLowerScoreField.setText(Integer.toString(player1Board.getBottom()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tLgStField.setText(Integer.toString(dieGroup.getLargeStraight()));
                player2Board.update(10);
                player2Board.largeStraight = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tLowerScoreField.setText(Integer.toString(player2Board.getBottom()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            lgStraightButton.setEnabled(false);
            largeStraight = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_lgStraightButtonActionPerformed

    private void yahtzeeButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_yahtzeeButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getYahtzee()));
}//GEN-LAST:event_yahtzeeButtonMouseEntered

    private void yahtzeeButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_yahtzeeButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_yahtzeeButtonMouseExited

    private void yahtzeeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yahtzeeButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yYahtzeeField.setText(Integer.toString(dieGroup.getYahtzee()));
                player1Board.update(11);
                player1Board.yahtzee = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yLowerScoreField.setText(Integer.toString(player1Board.getBottom()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tYahtzeeField.setText(Integer.toString(dieGroup.getYahtzee()));
                player2Board.update(11);
                player2Board.yahtzee = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tLowerScoreField.setText(Integer.toString(player2Board.getBottom()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            yahtzeeButton.setEnabled(false);
            yahtzee = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_yahtzeeButtonActionPerformed

    private void chanceButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chanceButtonMouseEntered
        possibleScore.setText(Integer.toString(dieGroup.getChance()));
}//GEN-LAST:event_chanceButtonMouseEntered

    private void chanceButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chanceButtonMouseExited
        possibleScore.setText("");
}//GEN-LAST:event_chanceButtonMouseExited

    private void chanceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chanceButtonActionPerformed
        if (rollCount != 0)
        {
            if (player == 1)
            {
                if (dieGroup.isYahtzee())
                    player1Board.yahtzeeCount++;
                yChanceField.setText(Integer.toString(dieGroup.getChance()));
                player1Board.update(12);
                player1Board.chance = true;
                if (!onePlayer)
                {
                    player = 2;
                    currentPlayer.setText("Player 2");
                }
                yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                yLowerScoreField.setText(Integer.toString(player1Board.getBottom()));
                yTotalScore.setText(Integer.toString(player1Board.getTotal()));
            }
            else if (player == 2)
            {
                if (dieGroup.isYahtzee())
                    player2Board.yahtzeeCount++;
                tChanceField.setText(Integer.toString(dieGroup.getChance()));
                player2Board.update(12);
                player2Board.chance = true;
                player = 1;
                currentPlayer.setText("Player 1");
                tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                tLowerScoreField.setText(Integer.toString(player2Board.getBottom()));
                tTotalScore.setText(Integer.toString(player2Board.getTotal()));
            }
            else
            {
                // shouldn't happen
            }
            rollCount = 0;
            rollButton.setEnabled(true);
            chanceButton.setEnabled(false);
            chance = true;
            unlock();
            repaintDie();
            disableAll();
            initialRoll = true;
            checkWin();
        }
}//GEN-LAST:event_chanceButtonActionPerformed

    private void yFourFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yFourFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_yFourFieldActionPerformed

    private void ySixFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ySixFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ySixFieldActionPerformed

    private void yUpperScoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yUpperScoreActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_yUpperScoreActionPerformed

    private void tOneFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tOneFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tOneFieldActionPerformed

    private void tThreeKindFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tThreeKindFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tThreeKindFieldActionPerformed

    private void tUpperScoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tUpperScoreActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tUpperScoreActionPerformed

    private void tSixFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tSixFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tSixFieldActionPerformed

    private void tFourFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tFourFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tFourFieldActionPerformed

    private void yChanceFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yChanceFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_yChanceFieldActionPerformed

    private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitButtonActionPerformed
        // shows an option dialog in which you can save the current program state
        Object[] options = {"Yes, please", "No way!"};
        int n = JOptionPane.showOptionDialog(null,
               "Would you like to save before closing?",
               "Are you sure?!",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.QUESTION_MESSAGE,
               null,     //do not use a custom Icon
               options,  //the titles of buttons
               options[0]); //default button title
       if (n == JOptionPane.YES_OPTION)
           save();
       else
       {
            System.exit(0);
       }
    }//GEN-LAST:event_quitButtonActionPerformed

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
       
}//GEN-LAST:event_exitMenuItemActionPerformed

    private void openItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openItemActionPerformed
        load();
}//GEN-LAST:event_openItemActionPerformed

    private void saveItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveItemActionPerformed
        save();
}//GEN-LAST:event_saveItemActionPerformed

    private void exitMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuActionPerformed
        // shows an option dialog in which you can save the current program state
        Object[] options = {"Yes, please", "No way!"};
        int n = JOptionPane.showOptionDialog(null,
               "Would you like to save before closing?",
               "Are you sure?!",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.QUESTION_MESSAGE,
               null,     //do not use a custom Icon
               options,  //the titles of buttons
               options[0]); //default button title
       if (n == JOptionPane.YES_OPTION)
           save();
       else
       {
            System.exit(0);
       }
    }//GEN-LAST:event_exitMenuActionPerformed

    private void newGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newGameActionPerformed
        // makes it the initial roll
        initialRoll = true;
        totalRoll = 0;
        rollCount = 0;
        repaintDie();
        unlock();
        rollButton.setEnabled(true);
        // makes a brand new scoreboard
        player1Board = new Scoreboard();
        player2Board = new Scoreboard();
        // resets all of the scores to 0
        for (int i = 0; i < 13; i++)
        {
            player1Board.scores[i] = 0;
            player2Board.scores[i] = 0;
        }
        // enables all of the buttons
        enableAll();
        // sets the player back to 1
        player = 1;
        // resets all of the fields
        currentPlayer.setText("Player 1");
        tOneField.setText("");
        yOneField.setText("");
        tTwoField.setText("");
        yTwoField.setText("");
        tThreeField.setText("");
        yThreeField.setText("");
        tFourField.setText("");
        yFourField.setText("");
        tFiveField.setText("");
        yFiveField.setText("");
        tSixField.setText("");
        ySixField.setText("");
        tThreeKindField.setText("");
        yThreeKindField.setText("");
        tFourKindField.setText("");
        yFourKindField.setText("");
        tFullHouseField.setText("");
        yFullHouseField.setText("");
        tSmStField.setText("");
        ySmStField.setText("");
        tLgStField.setText("");
        yLgStField.setText("");
        tBonusField.setText("");
        yBonusField.setText("");
        tUpperScore.setText("");
        yUpperScore.setText("");
        tYahtzeeField.setText("");
        yYahtzeeField.setText("");
        tChanceField.setText("");
        yChanceField.setText("");
        tYahtzeeBonus.setText("");
        yYahtzeeBonus.setText("");
        yLowerScoreField.setText("");
        tLowerScoreField.setText("");
        tTotalScore.setText("");
        yTotalScore.setText("");

        // renables the ability to select the amount of players
        onePlayerOption.setEnabled(true);
        twoPlayerOption.setEnabled(true);

        updateHighScores();
    }//GEN-LAST:event_newGameActionPerformed

    private void onePlayerOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onePlayerOptionActionPerformed
        onePlayer = true;
        player2Label.setText("NA");
    }//GEN-LAST:event_onePlayerOptionActionPerformed

    private void twoPlayerOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_twoPlayerOptionActionPerformed
        onePlayer = false;
        player2Label.setText("Player 2");
    }//GEN-LAST:event_twoPlayerOptionActionPerformed

    private void helpMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpMenuItemActionPerformed

        // found this code online
        String url = "http://en.wikipedia.org/wiki/Yahtzee";
	String os = System.getProperty("os.name").toLowerCase();
        Runtime rt = Runtime.getRuntime();

	try{

	    if (os.indexOf( "win" ) >= 0) {
 
	        // this doesn't support showing urls in the form of "page.html#nameLink"
	        rt.exec( "rundll32 url.dll,FileProtocolHandler " + url);

	    } else if (os.indexOf( "mac" ) >= 0) {

	        rt.exec( "open " + url);

            } else if (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0) {

	        // Do a best guess on unix until we get a platform independent way
	        // Build a list of browsers to try, in this order.
	        String[] browsers = {"epiphany", "firefox", "mozilla", "konqueror",
	       			             "netscape","opera","links","lynx"};

	        // Build a command string which looks like "browser1 "url" || browser2 "url" ||..."
	        StringBuffer cmd = new StringBuffer();
	        for (int i=0; i<browsers.length; i++)
	            cmd.append( (i==0  ? "" : " || " ) + browsers[i] +" \"" + url + "\" ");

	        rt.exec(new String[] { "sh", "-c", cmd.toString() });

           } else {
                return;
           }
       }catch (Exception e){
	    return;
       }
      return;
    }//GEN-LAST:event_helpMenuItemActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel LBLabel;
    private javax.swing.JLabel UBLabel;
    private javax.swing.JLabel USLabel;
    private javax.swing.JPanel bottomButtonPanel;
    private javax.swing.JPanel bottomScorePanel;
    private javax.swing.JButton chanceButton;
    private javax.swing.JLabel currentPlayer;
    private javax.swing.JMenuItem exitMenu;
    private javax.swing.JMenu exitMenuItem;
    private javax.swing.JButton fivesButton;
    private javax.swing.JButton fourkindButton;
    private javax.swing.JButton foursButton;
    private javax.swing.JButton fullhouseButton;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenuItem helpMenuItem;
    private javax.swing.JTextArea highScores;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JButton lgStraightButton;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem newGame;
    private javax.swing.JRadioButtonMenuItem onePlayerOption;
    private javax.swing.JPanel oneSixPanel;
    private javax.swing.JButton onesButton;
    private javax.swing.JMenuItem openItem;
    private java.awt.Label player1Label;
    private java.awt.Label player2Label;
    private javax.swing.ButtonGroup playerButtonGroup;
    private javax.swing.JMenu playerMenu;
    private javax.swing.JLabel possibleScore;
    private javax.swing.JButton quitButton;
    private javax.swing.JButton rollButton;
    private javax.swing.JMenuItem saveItem;
    private javax.swing.JPanel scoreButtonPanel;
    private javax.swing.JButton sixesButton;
    private javax.swing.JButton smStraightButton;
    private javax.swing.JTextField tBonusField;
    private javax.swing.JTextField tChanceField;
    private javax.swing.JTextField tFiveField;
    private javax.swing.JTextField tFourField;
    private javax.swing.JTextField tFourKindField;
    private javax.swing.JTextField tFullHouseField;
    private javax.swing.JTextField tLgStField;
    private javax.swing.JTextField tLowerScoreField;
    private javax.swing.JTextField tOneField;
    private javax.swing.JTextField tSixField;
    private javax.swing.JTextField tSmStField;
    private javax.swing.JTextField tThreeField;
    private javax.swing.JTextField tThreeKindField;
    private javax.swing.JTextField tTotalScore;
    private javax.swing.JTextField tTwoField;
    private javax.swing.JTextField tUpperScore;
    private javax.swing.JTextField tYahtzeeBonus;
    private javax.swing.JTextField tYahtzeeField;
    private javax.swing.JButton threekindButton;
    private javax.swing.JButton threesButton;
    private javax.swing.JPanel topScorePanel;
    private javax.swing.JLabel totalScoreLabel;
    private javax.swing.JRadioButtonMenuItem twoPlayerOption;
    private javax.swing.JButton twosButton;
    private javax.swing.JTextField yBonusField;
    private javax.swing.JTextField yChanceField;
    private javax.swing.JTextField yFiveField;
    private javax.swing.JTextField yFourField;
    private javax.swing.JTextField yFourKindField;
    private javax.swing.JTextField yFullHouseField;
    private javax.swing.JTextField yLgStField;
    private javax.swing.JTextField yLowerScoreField;
    private javax.swing.JTextField yOneField;
    private javax.swing.JTextField ySixField;
    private javax.swing.JTextField ySmStField;
    private javax.swing.JTextField yThreeField;
    private javax.swing.JTextField yThreeKindField;
    private javax.swing.JTextField yTotalScore;
    private javax.swing.JTextField yTwoField;
    private javax.swing.JTextField yUpperScore;
    private javax.swing.JTextField yYahtzeeBonus;
    private javax.swing.JTextField yYahtzeeField;
    private javax.swing.JLabel yahtzeeBonusLabel;
    private javax.swing.JButton yahtzeeButton;
    // End of variables declaration//GEN-END:variables

    /**
     * unlocks all of the die
     */
    private void unlock()
    {
        die1.setLocked(false);
        die2.setLocked(false);
        die3.setLocked(false);
        die4.setLocked(false);
        die5.setLocked(false);
    }

    /**
     * repaints all of the die
     */
    private void repaintDie()
    {
        die1.repaint();
        die2.repaint();
        die3.repaint();
        die4.repaint();
        die5.repaint();
    }

    /** disables all of the buttons
     *
     */
    private void disableAll()
    {
        if (rollCount == 0)
        {
            onesButton.setEnabled(false);
            twosButton.setEnabled(false);
            threesButton.setEnabled(false);
            foursButton.setEnabled(false);
            fivesButton.setEnabled(false);
            sixesButton.setEnabled(false);
            threekindButton.setEnabled(false);
            fourkindButton.setEnabled(false);
            fullhouseButton.setEnabled(false);
            smStraightButton.setEnabled(false);
            lgStraightButton.setEnabled(false);
            yahtzeeButton.setEnabled(false);
            chanceButton.setEnabled(false);
        }
        else
        {
        if (player == 1)
        {
            if(player1Board.ones)
                onesButton.setEnabled(false);
            if(player1Board.twos)
                twosButton.setEnabled(false);
            if(player1Board.threes)
                threesButton.setEnabled(false);
            if(player1Board.fours)
                foursButton.setEnabled(false);
            if(player1Board.fives)
                fivesButton.setEnabled(false);
            if(player1Board.sixes)
                sixesButton.setEnabled(false);
            if(player1Board.threeKind)
                threekindButton.setEnabled(false);
            if(player1Board.fourKind)
                fourkindButton.setEnabled(false);
            if(player1Board.fullHouse)
                fullhouseButton.setEnabled(false);
            if(player1Board.smallStraight)
                smStraightButton.setEnabled(false);
            if(player1Board.largeStraight)
                lgStraightButton.setEnabled(false);
            if(player1Board.yahtzee)
                yahtzeeButton.setEnabled(false);
            if(player1Board.chance)
                chanceButton.setEnabled(false);
        }
        else 
        {
            if(player2Board.ones)
                onesButton.setEnabled(false);
            if(player2Board.twos)
                twosButton.setEnabled(false);
            if(player2Board.threes)
                threesButton.setEnabled(false);
            if(player2Board.fours)
                foursButton.setEnabled(false);
            if(player2Board.fives)
                fivesButton.setEnabled(false);
            if(player2Board.sixes)
                sixesButton.setEnabled(false);
            if(player2Board.threeKind)
                threekindButton.setEnabled(false);
            if(player2Board.fourKind)
                fourkindButton.setEnabled(false);
            if(player2Board.fullHouse)
                fullhouseButton.setEnabled(false);
            if(player2Board.smallStraight)
                smStraightButton.setEnabled(false);
            if(player2Board.largeStraight)
                lgStraightButton.setEnabled(false);
            if(player2Board.yahtzee)
                yahtzeeButton.setEnabled(false);
            if(player2Board.chance)
                chanceButton.setEnabled(false);
        }
        }

    }

    /**
     * enables all of the buttons
     */
    private void enableAll()
    {
        if (player == 1)
        {
            if(!player1Board.ones)
                onesButton.setEnabled(true);
            if(!player1Board.twos)
                twosButton.setEnabled(true);
            if(!player1Board.threes)
                threesButton.setEnabled(true);
            if(!player1Board.fours)
                foursButton.setEnabled(true);
            if(!player1Board.fives)
                fivesButton.setEnabled(true);
            if(!player1Board.sixes)
                sixesButton.setEnabled(true);
            if(!player1Board.threeKind)
                threekindButton.setEnabled(true);
            if(!player1Board.fourKind)
                fourkindButton.setEnabled(true);
            if(!player1Board.fullHouse)
                fullhouseButton.setEnabled(true);
            if(!player1Board.smallStraight)
                smStraightButton.setEnabled(true);
            if(!player1Board.largeStraight)
                lgStraightButton.setEnabled(true);
            if(!player1Board.yahtzee)
                yahtzeeButton.setEnabled(true);
            if(!player1Board.chance)
                chanceButton.setEnabled(true);
        }
        else 
        {
            if(!player2Board.ones)
                onesButton.setEnabled(true);
            if(!player2Board.twos)
                twosButton.setEnabled(true);
            if(!player2Board.threes)
                threesButton.setEnabled(true);
            if(!player2Board.fours)
                foursButton.setEnabled(true);
            if(!player2Board.fives)
                fivesButton.setEnabled(true);
            if(!player2Board.sixes)
                sixesButton.setEnabled(true);
            if(!player2Board.threeKind)
                threekindButton.setEnabled(true);
            if(!player2Board.fourKind)
                fourkindButton.setEnabled(true);
            if(!player2Board.fullHouse)
                fullhouseButton.setEnabled(true);
            if(!player2Board.smallStraight)
                smStraightButton.setEnabled(true);
            if(!player2Board.largeStraight)
                lgStraightButton.setEnabled(true);
            if(!player2Board.yahtzee)
                yahtzeeButton.setEnabled(true);
            if(!player2Board.chance)
                chanceButton.setEnabled(true);
        }
    }
    /**
     * load will pop up a file chooser and allow the user to load a previous
     * program state and once loaded the user can add more scores to the state
     */
    private void load()
    {
        initialRoll = false;
        // creates a new filechooser
             fileLoad = new JFileChooser();
             fileLoad.showOpenDialog(null);
             fileLoad.setFileSelectionMode(JFileChooser.FILES_ONLY);
             File file = fileLoad.getSelectedFile();
             file.setWritable(true);
             try
             {
                 // creates the input streams
                 FileInputStream fis = new FileInputStream(file);
                 ObjectInputStream ois = new ObjectInputStream(fis);
                 // loads the info needed to keep the game accurate
                 player = ois.readInt();
                 totalRoll = ois.readInt();
                 onePlayer = ois.readBoolean();
                 if (onePlayer)
                 {
                     player2Label.setText("NA");
                     onePlayerOption.setSelected(true);
                 }
                 else
                 {
                     player2Label.setText("Player 2");
                     twoPlayerOption.setSelected(true);
                 }

                 // loads the scoreboards
                 player1Board = (Scoreboard) ois.readObject();
                 player2Board = (Scoreboard) ois.readObject();

                 rollCount = 0;

                 tOneField.setText("");
        yOneField.setText("");
        tTwoField.setText("");
        yTwoField.setText("");
        tThreeField.setText("");
        yThreeField.setText("");
        tFourField.setText("");
        yFourField.setText("");
        tFiveField.setText("");
        yFiveField.setText("");
        tSixField.setText("");
        ySixField.setText("");
        tThreeKindField.setText("");
        yThreeKindField.setText("");
        tFourKindField.setText("");
        yFourKindField.setText("");
        tFullHouseField.setText("");
        yFullHouseField.setText("");
        tSmStField.setText("");
        ySmStField.setText("");
        tLgStField.setText("");
        yLgStField.setText("");
        tBonusField.setText("");
        yBonusField.setText("");
        tUpperScore.setText("");
        yUpperScore.setText("");
        tYahtzeeField.setText("");
        yYahtzeeField.setText("");
        tChanceField.setText("");
        yChanceField.setText("");
        tYahtzeeBonus.setText("");
        yYahtzeeBonus.setText("");
        yLowerScoreField.setText("");
        tLowerScoreField.setText("");
        tTotalScore.setText("");
        yTotalScore.setText("");
                 // loads up all of the info into the textfields
                 currentPlayer.setText("Player " + Integer.toString(player));
                 if (player1Board.ones)
                     yOneField.setText(Integer.toString(player1Board.scores[0]));
                 if (player2Board.ones)
                     tOneField.setText(Integer.toString(player2Board.scores[0]));
                 if (player1Board.twos)
                     yTwoField.setText(Integer.toString(player1Board.scores[1]));
                 if (player2Board.twos)
                     tTwoField.setText(Integer.toString(player2Board.scores[1]));
                 if (player1Board.threes)
                     yThreeField.setText(Integer.toString(player1Board.scores[2]));
                 if (player2Board.threes)
                     tThreeField.setText(Integer.toString(player2Board.scores[2]));
                 if (player1Board.fours)
                     yFourField.setText(Integer.toString(player1Board.scores[3]));
                 if (player2Board.fours)
                     tFourField.setText(Integer.toString(player2Board.scores[3]));
                 if (player1Board.fives)
                     yFiveField.setText(Integer.toString(player1Board.scores[4]));
                 if (player2Board.fives)
                     tFiveField.setText(Integer.toString(player2Board.scores[4]));
                 if (player1Board.sixes)
                     ySixField.setText(Integer.toString(player1Board.scores[5]));
                 if (player2Board.sixes)
                     tSixField.setText(Integer.toString(player2Board.scores[5]));
                 if (player1Board.threeKind)
                     yThreeKindField.setText(Integer.toString(player1Board.scores[6]));
                 if (player2Board.threeKind)
                     tThreeKindField.setText(Integer.toString(player2Board.scores[6]));
                 if (player1Board.fourKind)
                     yFourKindField.setText(Integer.toString(player1Board.scores[7]));
                 if (player2Board.ones)
                     tFourKindField.setText(Integer.toString(player2Board.scores[7]));
                 if (player1Board.fullHouse)
                     yFullHouseField.setText(Integer.toString(player1Board.scores[8]));
                 if (player2Board.fullHouse)
                     tFullHouseField.setText(Integer.toString(player2Board.scores[8]));
                 if (player1Board.smallStraight)
                     ySmStField.setText(Integer.toString(player1Board.scores[9]));
                 if (player2Board.smallStraight)
                     tSmStField.setText(Integer.toString(player2Board.scores[9]));
                 if (player1Board.largeStraight)
                     yLgStField.setText(Integer.toString(player1Board.scores[10]));
                 if (player2Board.largeStraight)
                     tLgStField.setText(Integer.toString(player2Board.scores[10]));
                 if (player1Board.yahtzee)
                     yYahtzeeField.setText(Integer.toString(player1Board.scores[11]));
                 if (player2Board.yahtzee)
                     tYahtzeeField.setText(Integer.toString(player2Board.scores[11]));
                 if (player1Board.chance)
                     yChanceField.setText(Integer.toString(player1Board.scores[12]));
                 if (player2Board.chance)
                     tChanceField.setText(Integer.toString(player2Board.scores[12]));
                 tUpperScore.setText(Integer.toString(player2Board.getTop()));
                 yUpperScore.setText(Integer.toString(player1Board.getTop()));
                 tBonusField.setText(Integer.toString(player2Board.getTopBonus()));
                 yBonusField.setText(Integer.toString(player1Board.getTopBonus()));
                 tYahtzeeBonus.setText(Integer.toString(player2Board.getYahtzeeBonus()));
                 yYahtzeeBonus.setText(Integer.toString(player1Board.getYahtzeeBonus()));
                 tLowerScoreField.setText(Integer.toString(player2Board.getBottom()));
                 yLowerScoreField.setText(Integer.toString(player1Board.getBottom()));
                 tTotalScore.setText(Integer.toString(player2Board.getTotal()));
                 yTotalScore.setText(Integer.toString(player1Board.getTotal()));
                 initialRoll = true;

                 unlock();
                 repaintDie();
                 // closes the input streams
                 ois.close();
                 fis.close();
             }
             // catches an IOException
             catch (IOException e)
             {
                 System.out.println ("IO exception = " + e );
             }
             // catches a class not found exception
             catch (ClassNotFoundException e)
             {
                 System.out.println("OOps");
             }
/**
 * allows the user to save the current state of the program for later editing
 * uses a file chooser just like load
 */
        }
        private void save()
        {
            // new filechooser
            saveFile = new JFileChooser();
            saveFile.showSaveDialog(null);
            File file = saveFile.getSelectedFile();
            try
            {
                // creates new output streams
                FileOutputStream fos = new FileOutputStream(file);
                ObjectOutputStream file_out = new ObjectOutputStream(fos);
         
                    // writes each shape to the output stream
                    file_out.writeInt(player);
                    file_out.writeInt(totalRoll);
                    file_out.writeBoolean(onePlayer);
                    file_out.writeObject(player1Board);
                    file_out.writeObject(player2Board);
                // closes the streams
                file_out.close();
                fos.close();
        }
            // catches an IOException which shouldn't happen
            catch (IOException e)
            {
            System.out.println ("IO exception = " + e );
            }
        }
        /**
         * checks if all the entries are scored or not and will display a dialog
         * box with the final scores if the game is over
         */
        private void checkWin()
        {
            totalRoll++;
            if (onePlayer)
            {
                if (totalRoll == 13)
                {
                    JOptionPane.showMessageDialog(null,
                            "Player 1 Total: " + player1Board.getTotal(),"Final Scores",
                            JOptionPane.OK_OPTION);

                    stats = new File("stats.txt");

//                    names = new File("names.txt");
                    
                    try
                    {
//                         // creates new output streams
                         FileOutputStream fos = new FileOutputStream(stats);
                         ObjectOutputStream file_out = new ObjectOutputStream(fos);


                         if (scores != null)
                         {
                             // determines if the current total is high enough
                             // to write to the top 10 file
                         if (player1Board.getTotal() >= scores[9])
                         {
//                             file_out.writeInt(player1Board.getTotal());
                             JOptionPane.showMessageDialog(null, "New Top 10 Score!",
                                     "Top 10",
                                     JOptionPane.WARNING_MESSAGE);
                             // allow user to input his/her name
                             player1Name = JOptionPane.showInputDialog(null, "Enter Your name",
                                     "New High Score", JOptionPane.QUESTION_MESSAGE);
//                             file_out2.writeUTF(player1Name);
                             highScore.addScore(player1Board.getTotal(), player1Name);
//                             updateNamesArray(player1Board.getTotal(), player1Name);
                         }

                         file_out.writeObject(highScore);


                         }
                         else
                         {
                             JOptionPane.showMessageDialog(null, "New Top 10 Score!",
                                     "Top 10",
                                     JOptionPane.WARNING_MESSAGE);
                         player1Name = JOptionPane.showInputDialog(null, "Enter Your name",
                                     "New High Score", JOptionPane.QUESTION_MESSAGE);
                         highScore.addScore(player1Board.getTotal(), player1Name);
                         file_out.writeObject(highScore);
                         }

                         file_out.close();
                         fos.close();
                         }

                    
                     // catches an IOException which shouldn't happen
                     catch (IOException e)
                     {
                         System.out.println ("IO exception 13 = " + e );
                     }
                    updateHighScores();
                    

                }
            }
            if (totalRoll == 26)
            {
                // shows a message dialog displaying the final scores
                JOptionPane.showMessageDialog(null,
               "Player 1 Total: " + player1Board.getTotal() + "\n"
               + "Player 2 Total: " + player2Board.getTotal(),"Final Scores",
               JOptionPane.OK_OPTION);

                stats = new File("stats.txt");
//                names = new File("names.txt");
                    try
                    {
                         // creates new output streams
                         FileOutputStream fos = new FileOutputStream(stats);
                         ObjectOutputStream file_out = new ObjectOutputStream(fos);

//                         FileOutputStream fos2 = new FileOutputStream(names);
//                         DataOutputStream file_out2 = new DataOutputStream(fos2);

                         if (scores != null)
                         {
                         // checks if the current games total is a top 10 score
                         if (player1Board.getTotal() >= scores[9])
                         {
                             // writes it to the file if it is
//                             file_out.writeInt(player1Board.getTotal());
                             // let the user know
                             JOptionPane.showMessageDialog(null, "New Top 10 Score!" + "\n" +
                                     "Player 1 " + player1Board.getTotal(),
                                     "Top 10",
                                     JOptionPane.WARNING_MESSAGE);
                             
                             // allow user to input his/her name
                             player1Name = JOptionPane.showInputDialog(null, "Enter Your name",
                                     "New High Score", JOptionPane.QUESTION_MESSAGE);
//                             file_out2.writeUTF(player1Name);
                             highScore.addScore(player1Board.getTotal(), player1Name);
//                             updateNamesArray(player1Board.getTotal(), player1Name);

                         }


                         // checks if the current games total is a top 10 score
                         if (player2Board.getTotal() >= scores[9])
                         {
                             // writes it to the file if it is
//                             file_out.writeInt(player2Board.getTotal());
                             // lets the user know
                             JOptionPane.showMessageDialog(null, "New Top 10 Score!" + "\n" +
                                     "Player 2 " + player2Board.getTotal(),
                                     "Top 10",
                                     JOptionPane.WARNING_MESSAGE);
                             // allow user to input his/her name
                             player2Name = JOptionPane.showInputDialog(null, "Enter Your name",
                                     "New High Score", JOptionPane.QUESTION_MESSAGE);
//                             file_out2.writeUTF(player2Name);
                             highScore.addScore(player2Board.getTotal(), player2Name);
//                             updateNamesArray(player2Board.getTotal(), player2Name);
                         }

                         file_out.writeObject(highScore);

                         }
              
                         
                         // closes the streams
                         file_out.close();
                         fos.close();
                         
                     }
                     // catches an IOException which shouldn't happen
                     catch (IOException e)
                     {
                         System.out.println ("IO exception 26 = " + e );
                     }
                // updates the high scores
                    updateHighScores();
                

        }
                
        }
        /**
         * loads the high score file and shows the scores in the text area
         */

        private void updateHighScores() 
        {
            // sets the stats file to the text file
            stats = new File("stats.txt");
//            names = new File("names.txt");

            // determines if the file exists
            if (stats.exists())
            {
                try
                {
                    // creates the input streams
                    FileInputStream fis = new FileInputStream(stats);
                    ObjectInputStream ois = new ObjectInputStream(fis);


                    // creates the high score array which will hold the scores
                    scores = new int[10];
                    namesArray = new String[10];

                    highScore = (HighScores) ois.readObject();
                    scores = highScore.getScores();
                    namesArray = highScore.getNames();

                // closes the input streams
                ois.close();
                fis.close();
                }
                catch (Exception e)
            {
                System.out.println ("IO exception high score= " + e );
            }

                // loop runs through the high score array and updates the highScores
                // textarea
                highScores.setText(null);
                for (int i = 0; i < 10; i++)
                {
                    if (scores[i] != 0)
                    {
                        highScores.append((i+1) + ": " + Integer.toString(scores[i]) +
                                " " + namesArray[i] + "\n");
                    }
                }

        }
        else
            System.out.println("No Stats File Found");
        }


       
}
